#pragma once

#include "ClearAssociationAction.h"

#include "Association.h"
#include "InputPin.h"

namespace uml {

ClearAssociationAction::ClearAssociationAction(const QString& umlType)
    : Action(umlType) {}

void ClearAssociationAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    association_ = JsonSerializable::create<Association>(json.value("association"), errorList);

    object_ = JsonSerializable::create<InputPin>(json.value("object"), errorList);

}

void ClearAssociationAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (association_) {
        QJsonObject association_json;
        association_->toJson(association_json);
        json.insert("association", association_json);
    }
    if (object_) {
        QJsonObject object_json;
        object_->toJson(object_json);
        json.insert("object", object_json);
    }
}

/// <summary>
/// association getter
/// The Association to be cleared.
/// </summary>
shared_ptr<Association> ClearAssociationAction::association() const {
    return association_;
}

/// <summary>
/// association setter
/// The Association to be cleared.
/// </summary>
void ClearAssociationAction::setAssociation(shared_ptr<Association> value) {
    association_ = value;
}

/// <summary>
/// object getter
/// The InputPin that gives the object whose participation in the Association is to
/// be cleared.
/// </summary>
shared_ptr<InputPin> ClearAssociationAction::object() const {
    return object_;
}

/// <summary>
/// object setter
/// The InputPin that gives the object whose participation in the Association is to
/// be cleared.
/// </summary>
void ClearAssociationAction::setObject(shared_ptr<InputPin> value) {
    object_ = value;
}

} // namespace uml
